<template>
  <div class="contentView" v-loading="loading" :style="`height:${contentHeight}px`">
    <div class="routeHeader mb-5px">
      <el-button @click="clickRevrt">关 闭</el-button>
    </div>
    <el-table v-loading="loading" :data="list" border :height="tableHeight">
      <el-table-column
        v-for="(item, index) in allSchemasLabel"
        :key="index"
        :label="item.label"
        :min-width="item.width"
        align="center"
        show-overflow-tooltip
      >
        <template #default="scope">
          <div v-if="item.type == 'index'">{{ scope.$index + 1 }}</div>
          <div v-else-if="item.field === 'filePath'">
          <span style="cursor: pointer;" @click="previewFile(scope.row.filePath)">{{ scope.row.fileName }}</span>
          </div>
          <div v-else-if="item.field === 'dictOrderType'">
            <dict-tag :type="DICT_TYPE.MARKET_ORDER_TYPE" :value="scope.row.dictOrderType" />
          </div>
          <div v-else-if="item.field === 'dictDeliveryProjectType'">
            <dict-tag :type="DICT_TYPE.DELIVERY_PROJECT_TYPE" :value="scope.row.dictDeliveryProjectType" />
          </div>
          <div v-else-if="item.field === 'dictTaskStatus'">
            <dict-tag :type="DICT_TYPE.ORDER_TASK_STATUS" :value="scope.row.dictTaskStatus" />
          </div>
          <div v-else-if="item.field === 'dictTaskType'">
            <dict-tag :type="DICT_TYPE.ORDER_TASK_TYPE" :value="scope.row.dictTaskType" />
          </div>
          <div v-else-if="item.field === 'dictChangeType'">
            <dict-tag :type="DICT_TYPE.CHANGE_TYPE" :value="scope.row.dictChangeType" />
          </div>
          <div v-else>{{ scope.row[item.field] }}</div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import * as ProjectTaskOddApi from '@/api/orderManagement/projectTaskOdd'
import { useTagsViewStore } from '@/store/modules/tagsView'
const loading = ref(true) // 列表的加载中
const list = ref([]) // 列表的数据
const total = ref(0) // 列表的总页数
const { query } = useRoute() // 路由的查询
// defineOptions({ name: 'OddDetails' })
const allSchemasLabel = ref<any[]>([])
/** 查询列表 */
const getListLabel = async () => {
  let id = query.id as any
  loading.value = true
  try {
    const data = await ProjectTaskOddApi.getProjectTask(id)
    allSchemasLabel.value = data.labels
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
const previewFile = (url) => {
    window.open(url)
  }
// 返回
const tagsViewStore = useTagsViewStore()
const route = useRouter() // 路由
const clickRevrt = async () => {
  //获取当前路由并删除tagView
  tagsViewStore.delView(route.currentRoute.value)
  route.push({
    path: '/orderManagement/orderManagement/project/projectTaskOdd'
  })
}
const contentHeight = ref(0)
const tableHeight = ref(0)
onMounted(async () => {
  contentHeight.value = document.body.clientHeight - 127
  tableHeight.value = contentHeight.value - 70
  getListLabel()
})
</script>
